package com.sljr.mvndemo;

import java.io.File;

public class DirUtil {
	public static void makeDirs(String path) {
		if (null == path || path.isEmpty()) {
			return;
		}

		try {
			File file = new File(path);
			if (!file.exists()) {
				if(path.indexOf(".") > 0) {
					if(file.getParentFile().mkdirs()) 
						file.createNewFile();
				} else {
					file.mkdirs();
				}
			} 
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void clearPath(String path) {
		if (null == path || path.isEmpty()) {
			return;
		}

		File file = new File(path);
		if (file.isDirectory() && file.exists()) {
			File[] files = file.listFiles();
			for (File f : files) {
				if (f.isDirectory()) {
					clearPath(f.getPath());
				} else {
					boolean delete = f.delete();
					System.out.println(delete);
				}
			}
			file.delete();
		} else if (file.isFile()) {
			file.delete();
		}
	}
}
